<?php 
//  Xac Dinh Hang So Cho Dia chi tuyet doi 
    define ('BASE_URL','http://localhost:8080/mycms/');
    // Kiem tra xem co ket qua hay khong  
        function confirm_query($result,$query){
             global $dbc;
             if(!$result){
             die ("Query {$query} <br /> MySql Error  ".mysqli_error($dbc));
        }   
      
        }
          function redirect_to($page='index.php'){
            $url=BASE_URL.$page;
             header("Location:{$url}");
            exit();
        } 
        function the_excerpt($str){
           return substr($str,0,strrpos($str,' '));
        }
        function validate_id($id){
             if(isset($id) && filter_var($id,FILTER_VALIDATE_INT,array('min_range' =>1)))
             { $val_id=$id ;
             return $val_id;
             }
             else
             {
                return null;
             }
        }
        function get_page_by_id($id){
            global $dbc;
            $q="Select p.page_name,p.page_id,  p.content ,";
            $q.=" DATE_FORMAT(p.post_on, '%b %d, %Y') AS date, ";
            $q.=" CONCAT_WS(' ',u.first_name,u.last_name) AS name ,u.user_id";
            $q.=" FROM pages AS p ";
            $q.=" INNER JOIN users as u ";
            $q.=" USING (user_id) ";
            $q.=" where p.page_id ={$id}";
            $q.=" ORDER BY date ASC LIMIT 1";
            $result=mysqli_query($dbc,$q);
            confirm_query($result,$q);
            return $result;
        }
        function the_content($text){
            $sanitized=htmlentities($text,ENT_COMPAT,'UTF-8');
            str_replace(array("\r\n","\n"),array("<p>","</p>").$text);
        }
?>